﻿using CSLua;
using Mono.Cecil;
using System.Linq;

namespace CSLua
{
    public static class CustomAttributeUtils
    {
        public static bool GetCustomAttributeArguments<T>(this ICustomAttributeProvider _this,string attrName, ref T def)
        {
            var attr = _this.getAttribute(attrName);

            if (attr != null && attr.ConstructorArguments.Count > 0)
            {
                if (attr.ConstructorArguments.First().Value is T ret)
                {
                    def = ret;
                    return true;
                }
            }
            return false;
        }
    }
}
